// https://vuex.vuejs.org/zh-cn/intro.html
// make sure to call Vue.use(Vuex) if using a module system
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    avatarurl: "", //头像
    nickName: '', //昵称
    gender: '',
    brief: '', //简介
    title: "", //职称
    email: '',
    WX: '',
    type: "",      //转发参数type
    scene: '',
    inf_id:"",  //转发参数inf_id
    openid: '', //  登录的openid
    optid: '',  //转发的参数openid
    inf_source:'' 
  },
  mutations: {
    getMyData(state, data) {
      state.nickName = data.nickName
      state.gender = data.gender
      state.avatarurl = data.avatarUrl
      this.commit("setSto")

    },
    getNickName(state, data){
      state.nickName = data.nickName
      state.gender = data.gender
      this.commit("setSto")
    },
    getUrl(state, data) {
      console.log("vuex中的url--》" + data);
      state.avatarurl = data
      this.commit("setSto")

    },
    storageOpenid(state, data) {
      wx.getStorage({
        key: "userInfo",
        success: function (res) {
          state.openid = res.data.openid
        }
      });
    },
    //Storage存入openid
    getOpenid(state, data) {
      state.openid = data.openid
      this.commit("setSto")
    },
    //Storage存入 个人信息（设置内容）

    getSettingData(state, data) {
      state.brief = data.brief
      state.title = data.title
      state.email = data.email
      state.WX = data.wx
      this.commit("setSto")

    },
    //通过openid  获取de个人设置信息
    storageProfileData(state, data) {
      console.log(">>>>");
      console.log(data);

      state.type = data.type,
        state.WX = data.wx,
        state.title = data.title,
        state.avatarurl = data.avatarurl,
        state.email = data.email,
        state.brief = data.brief
      this.commit("setSto")

    },
    //获取转发参数openid。场景值并修改scene值  
    getScene(state, data) {
      console.log(data);
      if (data) {
        state.scene = data.scene;
        state.optid = data.query.openid;
        state.type = data.query.type;
        state.inf_id=data.query.inf_id;
        state.inf_source=data.query.inf_source;
        console.log(state.scene, state.optid, state.type,state.inf_source);
      }


    },

    //Storage存入方法   存入userinfo
    setSto(state) {
      let {
        avatarurl,
        nickName,
        gender,
        email,
        brief,
        title,
        WX,
        type,
        openid
      } = state
      wx.setStorage({
        key: "userInfo",
        data: {
          avatarurl,
          nickName,
          gender,
          brief,
          title,
          WX,
          email,
          type,
          openid
        }
      });
    },



  }
})

export default store
